<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\User;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('User', 'Users');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('User', 'Create User', [
    'modelClass' => 'User',
]), ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'user_id',
            'user_name',
 //           'password',
            'email:email',
            'register_date',
            [
                'attribute'=>'status',
                'value'=>function ($model, $key, $index, $column){
                    return $model->status == 1 ? 'ACTIVE' : 'DEACTIVE';
                    },
            ],
            // 'last_login_date',
            // 'last_login_ip',
            // 'expired_date',
            // 'session_id',
            // 'nick_name',
            // 'url:url',
            // 'department',
            // 'professional',
            // 'class',
            [
                'class' => 'yii\grid\ActionColumn',
                'visible'=>yii::$app->user->identity->checkAccess(User::ROLE_ADMIN),
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'visible'=>yii::$app->user->identity->checkAccess(User::ROLE_TEACHER),
                'template'=>'{ChangeStatus}',
                'buttons'=>[
                    'ChangeStatus'=>function($url, $model, $key)
                    {
                         return Html::a('Change Status', yii::$app->urlManager->createUrl(['user/changestatus','id'=>$model->user_id]));
                    },
                ],
            ],

        ],
    ]); ?>

</div>
